﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam4.Biz;
using MockPrjTeam4.Entity;
using MockPrjTeam4.Common;

namespace MockPrjTeam4.Pages.Views
{
    public partial class AddDepartment : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ddlCountry.DataSource = CountryBiz.GetListCountries();
            ddlCountry.DataBind();
            
            string popup = @"
            function popup(url, width, height)
            {
                var width = 500;
                var height = 400;
                var left = (screen.width - width) / 2;
                var top = (screen.height - height) / 2;
                var params = 'width=' + width + ', height=' + height;
                params += ', top=' + top + ', left=' + left;
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes
';
                params += ', status=no';
                params += ', toolbar=no';
                newwin = window.open(url, 'windowname5', params);
                if (window.focus) 
                { 
                    newwin.focus() 
                }
                return false;
            }
            </script>";
            string url = "PopupTypeofBusiness.aspx";
            string script = string.Format(@"<script> 
            function OpenWindows()
            {{ 
                popup('{0}');
            }}
            function popup(url, width, height)
            {{
                //var width = 500;
                //var height = 400;
                var left = (screen.width - width) / 2;
                var top = (screen.height - height) / 2;
                var params = 'width=' + width + ', height=' + height;
                params += ', top=' + top + ', left=' + left;
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=yes';
                params += ', scrollbars=no';
                params += ', status=no';
                params += ', toolbar=no';
                newwin = window.open(url, 'windowname5', params);
                if (window.focus) 
                {{ 
                    newwin.focus() 
                }}
                return false;
            }}
            </script>", url);

            if (!Page.ClientScript.IsStartupScriptRegistered("Mast"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
                    "Mast", script);
            }
        }

        protected void lkbtnTypeOfBusiness_Click(object sender, EventArgs e)
        {
            Response.Redirect("PopupTypeOfBusiness.aspx");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Departments dep = new Departments();
            dep.DepartmentName = txtDepName.Text;
            dep.BusinessId = Methods.ConvertNumber(hdfTypeOfBusinessId.Value);

            dep.ContactId = Methods.ConvertNumber(hdfContact.Value);
            dep.ShortDescription = txtDepShortDes.Text;
            dep.FullDescription = txtDepFullDes.Text;
            dep.CityTown = txtTown.Text;
            dep.County = txtCounty.Text;
            dep.CountryId = Methods.ConvertNumber(ddlCountry.Text);
            dep.PhoneNumber = txtPhoneNumber.Text;
            dep.Fax = txtFax.Text;
            dep.Email = txtEmail.Text;
            dep.WebAddress = txtWebAdd.Text;
            //dep.DirectorateId
            if (chkActive.Checked) dep.IsActive = true;
            else dep.IsActive = false;
            dep.PostCode = txtPostcode.Text;
            dep.AddressLine1 = txtAddLine1.Text;
            dep.AddressLine2 = txtAddLine2.Text;
            dep.AddressLine3 = txtAddLine3.Text;
            DepartmentsBiz.AddDepartment(dep);
            lblMessage.Text = "You added " + txtDepName.Text + " successfully";
            Response.Redirect("../Views/ListDepartments.aspx");
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Views/ListDepartments.aspx");
        }

//         protected void btnBack_Click(object sender, EventArgs e)
//         {
//             int i = 1;
//             Response.Redirect("ListDepartments.aspx?ID=" + i.ToString());
//         }
    }
}